from django.contrib.auth.backends import BaseBackend
from django.contrib.auth.hashers import check_password
from students.models import Student

class SchoolBackend(BaseBackend):
    def authenticate(self, request, username=None, password=None):
        try:
            user = Student.objects.get(student_id=username)
        except Student.DoesNotExist:
            return None

        pass_valid = check_password(password, user.password)

        if pass_valid:
            return user

        return None

    def get_user(self, user_id):
        try:
            return Student.objects.get(pk=user_id)
        except Student.DoesNotExist:
            return None
        